package campeonatofutebol.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Config {

	public Config() {

	}

	public static List<String> recuperaDadosHtml(String url, String busca){
		ArrayList<String> tableRowStrings = new ArrayList<String>();
		//Open a document from a valid URL using jsoup
		Document doc = null;
		try {
			doc = Jsoup.connect(url).get();

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


		//Once this document has loaded, select all <tr> tableRow elements into tableRows, with each
		//tableRow, collect all children, which will be <td>, into tableDatas Elements, test that Elements class for text,
		//if text exists, transfer the text of these children to a string, test that string for a substring, 
		//In this case, a date, if it contains this substring, add it to the created tableRowStrings ArrayList.
		//This function falsely returns a string with duplicated table row information.

		//Example Test Criteria, in reality this may be interfaced to a datetime or textbox widget
		//to facilitate an end-user defined search


		//select all <tr> or Table Row Elements
		Elements tableRows = doc.select(busca); // recupera da tabela .gameTable todos os <tr>
		for (Element tableRow : tableRows){
			
			if (tableRow.hasText()){
				String rowData = tableRow.text();
				tableRowStrings.add(rowData);
			}
		} 
		return tableRowStrings;
	}

}
